package com.efast.dmom.mgmt.service.mes.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.efast.cafe.framework.bean.ResultBean;
import com.efast.cafe.framework.util.SpringWebUtils;
import com.efast.dmom.mgmt.bean.mes.SoftDeleteUtilBean;
import com.efast.dmom.mgmt.dao.mes.MesSoftDeleteHistoryDao;
import com.efast.dmom.mgmt.dao.mes.TwBasLotDao;
import com.efast.dmom.mgmt.entity.mes.MesSoftDeleteHistory;
import com.efast.dmom.mgmt.entity.mes.TwBasLot;
import com.efast.dmom.mgmt.service.mes.MesSoftDeleteHistoryService;
import com.efast.dmom.mgmt.utils.Assist;
@Service
public class MesSoftDeleteHistoryServiceImpl implements MesSoftDeleteHistoryService {
	@Autowired
	private MesSoftDeleteHistoryDao mesSoftDeleteHistoryDao;
	
	@Autowired
	private TwBasLotDao twBasLotDao;
	
	private MesSoftDeleteHistory mesSoftDeleteHistory=null;

	@Override
	@Transactional
	public boolean softDelete(SoftDeleteUtilBean softDeleteUtilBean) {
		List<MesSoftDeleteHistory> list = new ArrayList<MesSoftDeleteHistory> ();
		boolean flag = false;
		if (softDeleteUtilBean.getCarType().equals("B") || softDeleteUtilBean.getCarType().equals("C")) {
			List<TwBasLot> selectTwBasLot = new ArrayList<TwBasLot>();
			if (softDeleteUtilBean.getSelfNumber() != null && softDeleteUtilBean.getSelfNumberLotName() == null) {
				Assist assist = new Assist();
				assist.setRequires(Assist.andEq("self_number", softDeleteUtilBean.getSelfNumber()));
				assist.setRequires(Assist.andNeq("state", "MERGED"));
				selectTwBasLot = twBasLotDao.selectTwBasLot(assist);
				softDeleteUtilBean.setSelfNumberLotName(selectTwBasLot.get(0).getLotName());
				softDeleteUtilBean.setVin(selectTwBasLot.get(0).getVin());
				softDeleteUtilBean.setOrderId(selectTwBasLot.get(0).getOrderId());
				softDeleteUtilBean.setOrderNo(selectTwBasLot.get(0).getOrderNo());
				softDeleteUtilBean.setOrderItemId(selectTwBasLot.get(0).getOrderItemId());
			} 
				// 软删除 lot历史表  tw_bas_lot_history
				softDeleteUtilBean.setTableName("tw_bas_lot_history");
				softDeleteUtilBean.setRange(1);
				List<MesSoftDeleteHistory> softDeleteTwBasLotHistory = softDeleteTwBasLotHistory(softDeleteUtilBean);
				for (MesSoftDeleteHistory mesSoftDeleteHistory : softDeleteTwBasLotHistory) {list.add(mesSoftDeleteHistory);}
				
				// 软删除 lot的关键件消耗表  tw_bas_lot_consumpation
				softDeleteUtilBean.setTableName("tw_bas_lot_consumpation");
				softDeleteUtilBean.setRange(1);
				List<MesSoftDeleteHistory> softDeleteTwBasLotHistory2 = softDeleteTwBasLotHistory(softDeleteUtilBean);
				for (MesSoftDeleteHistory mesSoftDeleteHistory : softDeleteTwBasLotHistory2) {list.add(mesSoftDeleteHistory);}
				
//				// 软删除物料拉动表 te_mes_outbound
//				softDeleteUtilBean.setTableName("te_mes_outbound");
//				softDeleteUtilBean.setRange(1);
//				List<MesSoftDeleteHistory> softDeleteTwBasLotHistory3 = softDeleteTwBasLotHistory(softDeleteUtilBean);
//				for (MesSoftDeleteHistory mesSoftDeleteHistory : softDeleteTwBasLotHistory3) {list.add(mesSoftDeleteHistory);}
				
				// lot测试记录 tw_bas_lot_testing
				softDeleteUtilBean.setTableName("tw_bas_lot_testing");
				softDeleteUtilBean.setRange(1);
				List<MesSoftDeleteHistory> softDeleteTwBasLotHistory6 = softDeleteTwBasLotHistory(softDeleteUtilBean);
				for (MesSoftDeleteHistory mesSoftDeleteHistory : softDeleteTwBasLotHistory6) {list.add(mesSoftDeleteHistory);}
				
				// 软删除lot数据采集记录 tw_bas_lot_data_collection
				softDeleteUtilBean.setTableName("tw_bas_lot_data_collection");
				softDeleteUtilBean.setRange(1);
				List<MesSoftDeleteHistory> softDeleteTwBasLotHistory7 = softDeleteTwBasLotHistory(softDeleteUtilBean);
				for (MesSoftDeleteHistory mesSoftDeleteHistory : softDeleteTwBasLotHistory7) {list.add(mesSoftDeleteHistory);}
				
				// 软删除缺陷记录表 qm_bas_defect_record
				softDeleteUtilBean.setTableName("qm_bas_defect_record");
				softDeleteUtilBean.setRange(2);
				List<MesSoftDeleteHistory> softDeleteTwBasLotHistory4 = softDeleteTwBasLotHistory(softDeleteUtilBean);
				for (MesSoftDeleteHistory mesSoftDeleteHistory : softDeleteTwBasLotHistory4) {list.add(mesSoftDeleteHistory);}
				
				// 软删除维修记录 qm_bas_defectrepair_record
				softDeleteUtilBean.setTableName("qm_bas_defectrepair_record");
				softDeleteUtilBean.setRange(2);
				List<MesSoftDeleteHistory> softDeleteTwBasLotHistory5 = softDeleteTwBasLotHistory(softDeleteUtilBean);
				for (MesSoftDeleteHistory mesSoftDeleteHistory : softDeleteTwBasLotHistory5) {list.add(mesSoftDeleteHistory);}
				
				// 软删除lot表记录 tw_bas_lot
				softDeleteUtilBean.setTableName("tw_bas_lot");
				softDeleteUtilBean.setRange(2);
				List<MesSoftDeleteHistory> softDeleteTwBasLotHistory3 = softDeleteTwBasLotHistory(softDeleteUtilBean);
				for (MesSoftDeleteHistory mesSoftDeleteHistory : softDeleteTwBasLotHistory3) {list.add(mesSoftDeleteHistory);}
				// 软删除检测线数据
				if (selectTwBasLot.size() == 0) {
					TwBasLot twBasLot = new TwBasLot();
					twBasLot.setSelfNumber(softDeleteUtilBean.getSelfNumber());
					twBasLot.setLotName(softDeleteUtilBean.getSelfNumberLotName());
					selectTwBasLot.add(twBasLot);
				}
				List<MesSoftDeleteHistory> sortDeleteTestLineDataByVin = sortDeleteTestLineDataByVin(selectTwBasLot, softDeleteUtilBean.getOprationType());
				for (MesSoftDeleteHistory mesSoftDeleteHistory : sortDeleteTestLineDataByVin) {list.add(mesSoftDeleteHistory);}
				// 删除成功
				flag = true;
			}
		if (softDeleteUtilBean.getCarType().equals("A")) {
			// 若传进来的数据只有vin，没有lotName
			if (softDeleteUtilBean.getVin() != null && softDeleteUtilBean.getVinLotName() == null) {
				Assist assist = new Assist();
				assist.setRequires(Assist.andEq("vin", softDeleteUtilBean.getVin()));
				List<TwBasLot> selectTwBasLot = twBasLotDao.selectTwBasLot(assist);
				if (selectTwBasLot.size()>0 && selectTwBasLot != null) {
					softDeleteUtilBean.setVinLotName(selectTwBasLot.get(0).getLotName());
					if (selectTwBasLot.get(0).getOrderId() != null && selectTwBasLot.get(0).getOrderId() != 0)
					softDeleteUtilBean.setOrderId(selectTwBasLot.get(0).getOrderId());
					if (selectTwBasLot.get(0).getOrderNo() != null && selectTwBasLot.get(0).getOrderNo() != "")
					softDeleteUtilBean.setOrderNo(selectTwBasLot.get(0).getOrderNo());
					if (selectTwBasLot.get(0).getOrderItemId() != null && selectTwBasLot.get(0).getOrderItemId() != 0)
					softDeleteUtilBean.setOrderItemId(selectTwBasLot.get(0).getOrderItemId());
				}
			}
			// 若传进来的数据只有selfName，没有lotName
			if (softDeleteUtilBean.getSelfNumber() != null && softDeleteUtilBean.getSelfNumberLotName() == null) {
				Assist assist = new Assist();
				assist.setRequires(Assist.andEq("self_number", softDeleteUtilBean.getSelfNumber()));
				assist.setRequires(Assist.andNeq("state", "MERGED"));
				List<TwBasLot> selectTwBasLot = twBasLotDao.selectTwBasLot(assist);
				softDeleteUtilBean.setSelfNumberLotName(selectTwBasLot.get(0).getLotName());
				if (selectTwBasLot.get(0).getOrderId() != null && selectTwBasLot.get(0).getOrderId() != 0)
				softDeleteUtilBean.setOrderId(selectTwBasLot.get(0).getOrderId());
				if (selectTwBasLot.get(0).getOrderNo() != null && selectTwBasLot.get(0).getOrderNo() != "")
				softDeleteUtilBean.setOrderNo(selectTwBasLot.get(0).getOrderNo());
				if (selectTwBasLot.get(0).getOrderItemId() != null && selectTwBasLot.get(0).getOrderItemId() != 0)
				softDeleteUtilBean.setOrderItemId(selectTwBasLot.get(0).getOrderItemId());
			}
			if (softDeleteUtilBean.getVinLotName().equals(softDeleteUtilBean.getSelfNumberLotName())) {
				softDeleteUtilBean.setVinLotName(null); 
			}
			// 软删除 lot历史表  tw_bas_lot_history
			softDeleteUtilBean.setTableName("tw_bas_lot_history");
			softDeleteUtilBean.setRange(3);
			List<MesSoftDeleteHistory> softDeleteTwBasLotHistory = softDeleteTwBasLotHistory(softDeleteUtilBean);
			for (MesSoftDeleteHistory mesSoftDeleteHistory : softDeleteTwBasLotHistory) {list.add(mesSoftDeleteHistory);}
			
			// 软删除 lot的关键件消耗表  tw_bas_lot_consumpation
			softDeleteUtilBean.setTableName("tw_bas_lot_consumpation");
			softDeleteUtilBean.setRange(3);
			List<MesSoftDeleteHistory> softDeleteTwBasLotHistory2 = softDeleteTwBasLotHistory(softDeleteUtilBean);
			for (MesSoftDeleteHistory mesSoftDeleteHistory : softDeleteTwBasLotHistory2) {list.add(mesSoftDeleteHistory);}
			
//			// 软删除物料拉动表 te_mes_outbound
//			softDeleteUtilBean.setTableName("te_mes_outbound");
//			softDeleteUtilBean.setRange(1);
//			List<MesSoftDeleteHistory> softDeleteTwBasLotHistory3 = softDeleteTwBasLotHistory(softDeleteUtilBean);
//			for (MesSoftDeleteHistory mesSoftDeleteHistory : softDeleteTwBasLotHistory3) {list.add(mesSoftDeleteHistory);}
			
			// lot测试记录 tw_bas_lot_testing
			softDeleteUtilBean.setTableName("tw_bas_lot_testing");
			softDeleteUtilBean.setRange(3);
			List<MesSoftDeleteHistory> softDeleteTwBasLotHistory6 = softDeleteTwBasLotHistory(softDeleteUtilBean);
			for (MesSoftDeleteHistory mesSoftDeleteHistory : softDeleteTwBasLotHistory6) {list.add(mesSoftDeleteHistory);}
			
			// 软删除lot数据采集记录 tw_bas_lot_data_collection
			softDeleteUtilBean.setTableName("tw_bas_lot_data_collection");
			softDeleteUtilBean.setRange(3);
			List<MesSoftDeleteHistory> softDeleteTwBasLotHistory7 = softDeleteTwBasLotHistory(softDeleteUtilBean);
			for (MesSoftDeleteHistory mesSoftDeleteHistory : softDeleteTwBasLotHistory7) {list.add(mesSoftDeleteHistory);}
			
			// 软删除缺陷记录表 qm_bas_defect_record
			softDeleteUtilBean.setTableName("qm_bas_defect_record");
			softDeleteUtilBean.setRange(4);
			List<MesSoftDeleteHistory> softDeleteTwBasLotHistory4 = softDeleteTwBasLotHistory(softDeleteUtilBean);
			for (MesSoftDeleteHistory mesSoftDeleteHistory : softDeleteTwBasLotHistory4) {list.add(mesSoftDeleteHistory);}
			
			// 软删除维修记录 qm_bas_defectrepair_record
			softDeleteUtilBean.setTableName("qm_bas_defectrepair_record");
			softDeleteUtilBean.setRange(4);
			List<MesSoftDeleteHistory> softDeleteTwBasLotHistory5 = softDeleteTwBasLotHistory(softDeleteUtilBean);
			for (MesSoftDeleteHistory mesSoftDeleteHistory : softDeleteTwBasLotHistory5) {list.add(mesSoftDeleteHistory);}
			
			// 软删除合拼表  tw_bas_lot_splice
			softDeleteUtilBean.setTableName("tw_bas_lot_splice");
			softDeleteUtilBean.setRange(4);
            List<MesSoftDeleteHistory> softDeleteTwBasLotHistory8 = softDeleteTwBasLotHistory(softDeleteUtilBean);
			for (MesSoftDeleteHistory mesSoftDeleteHistory : softDeleteTwBasLotHistory8) {list.add(mesSoftDeleteHistory);}
			
			// 软删除lot表记录 tw_bas_lot
			softDeleteUtilBean.setTableName("tw_bas_lot");
			softDeleteUtilBean.setRange(4);
			List<MesSoftDeleteHistory> softDeleteTwBasLotHistory3 = softDeleteTwBasLotHistory(softDeleteUtilBean);
			for (MesSoftDeleteHistory mesSoftDeleteHistory : softDeleteTwBasLotHistory3) {list.add(mesSoftDeleteHistory);}
			
			
			List<TwBasLot> lotlist = new ArrayList<TwBasLot>();
			TwBasLot twBasLot = new TwBasLot();
			twBasLot.setVin(softDeleteUtilBean.getVin());
			twBasLot.setLotName(softDeleteUtilBean.getVinLotName());
			lotlist.add(twBasLot);
			// 软删除检测线数据
			List<MesSoftDeleteHistory> sortDeleteTestLineDataByVin = sortDeleteTestLineDataByVin(lotlist, softDeleteUtilBean.getOprationType());
			for (MesSoftDeleteHistory mesSoftDeleteHistory : sortDeleteTestLineDataByVin) {list.add(mesSoftDeleteHistory);}
			// 删除成功
			flag = true;
		}
		mesSoftDeleteHistoryDao.addsSoftDeleteHistory(list);
		return flag;
	}
	
	/**
	 * 软删除检测线的数据
	 * 
	 * */
	public List<MesSoftDeleteHistory> sortDeleteTestLineDataByVin (List<TwBasLot> lot,String oprationType ) {
		List<MesSoftDeleteHistory> list = new ArrayList<MesSoftDeleteHistory>();
		List<String> tableList = new ArrayList<String>();
		
		// 检测线中四轮定位 qm_bas_testline_fourwheelpositioning
		tableList.add("qm_bas_testline_fourwheelpositioning");
		
		// 检测线中abs检测结果  qm_bas_testline_abs
		tableList.add("qm_bas_testline_abs");
		
		// 检测线中侧滑检测结果  qm_bas_testline_sideslip
		tableList.add("qm_bas_testline_sideslip");
		
		// 检测线中车速检测结果  qm_bas_testline_speed
		tableList.add("qm_bas_testline_speed");
		
		// 检测线中喇叭声级检测结果 qm_bas_testline_voice
		tableList.add("qm_bas_testline_voice");
		
		// 灯光检测结果  qm_bas_testline_light
		tableList.add("qm_bas_testline_light");
		
		// 制动检测结果  qm_bas_testline_braking
		tableList.add("qm_bas_testline_braking");
		
		// 报告基础信息 qm_bas_testline_carinfo
		tableList.add("qm_bas_testline_carinfo");
		
		for (TwBasLot twBasLot : lot) {
			if (twBasLot.getVin() == null || twBasLot.getVin() == "") {
			} else {
				for (String table : tableList) {
					Map<String,Object> map = new HashMap<String,Object>();
					map.put("table", table);
					map.put("lastUpdateTime", new Date());
					map.put("lastUpdateUser", SpringWebUtils.getRequestUser());
					map.put("vin", twBasLot.getVin());
					mesSoftDeleteHistory = new MesSoftDeleteHistory();
					Integer softDeletTestlineDateByVin = mesSoftDeleteHistoryDao.softDeletTestlineDateByVin(map);
					if (softDeletTestlineDateByVin != null && softDeletTestlineDateByVin != 0) {
						mesSoftDeleteHistory.setEffectRowCount(softDeletTestlineDateByVin == null ? 0:softDeletTestlineDateByVin);
						mesSoftDeleteHistory.setOperationType(oprationType);
						mesSoftDeleteHistory.setLotName(twBasLot.getLotName());
						mesSoftDeleteHistory.setVin(twBasLot.getVin()+"-A");
						mesSoftDeleteHistory.setDumyVin(twBasLot.getVin());
						mesSoftDeleteHistory.setTableName(table);
						mesSoftDeleteHistory.setCreateTime(new Date());
						mesSoftDeleteHistory.setCreateUser(SpringWebUtils.getRequestUser());
						mesSoftDeleteHistory.setLastupdateTime(new Date());
						mesSoftDeleteHistory.setLastupdateUser(SpringWebUtils.getRequestUser());
						list.add(mesSoftDeleteHistory);
					}
				}
			}
		}
		return list;
	}
	/**
	 * 软删除当是货车和专用车时 tw_bas_lot_history  tw_bas_lot_consumpation  te_mes_outbound
	 * 
	 * */
	public List<MesSoftDeleteHistory> softDeleteTwBasLotHistory (SoftDeleteUtilBean softDeleteUtilBean) {
		List<MesSoftDeleteHistory> list = new ArrayList<MesSoftDeleteHistory> ();
		softDeleteUtilBean.setUpdateTime(new Date());
		softDeleteUtilBean.setUpdateUser(SpringWebUtils.getRequestUser());
		Integer softDeleteTwBasLotHistory = null;
		if (softDeleteUtilBean.getRange() == 1) {
			softDeleteTwBasLotHistory = mesSoftDeleteHistoryDao.softDeleteBCSomeBylotName(softDeleteUtilBean);
		} else if (softDeleteUtilBean.getRange() == 2) {
			softDeleteTwBasLotHistory = mesSoftDeleteHistoryDao.softDeletSomeBCByVinAndLotName(softDeleteUtilBean);
		} else if (softDeleteUtilBean.getRange() == 3) {
			softDeleteTwBasLotHistory = mesSoftDeleteHistoryDao.softDeletSomeAByVinAndLotName(softDeleteUtilBean);
		} else if (softDeleteUtilBean.getRange() == 4) {
			softDeleteTwBasLotHistory = mesSoftDeleteHistoryDao.softDeletSomeAByVinOrSelfNumber(softDeleteUtilBean);
		}
		if (softDeleteTwBasLotHistory != null && softDeleteTwBasLotHistory != 0) {
			if (softDeleteUtilBean.getVinLotName() != null) {
				mesSoftDeleteHistory = new MesSoftDeleteHistory();
				mesSoftDeleteHistory.setEffectRowCount(softDeleteTwBasLotHistory == null ? 0:softDeleteTwBasLotHistory);
				mesSoftDeleteHistory.setOperationType(softDeleteUtilBean.getOprationType());
				mesSoftDeleteHistory.setLotName(softDeleteUtilBean.getVinLotName()+"-A");
				mesSoftDeleteHistory.setVin(softDeleteUtilBean.getVin()+"-A");
				mesSoftDeleteHistory.setDumyVin(softDeleteUtilBean.getVin());
				mesSoftDeleteHistory.setOrderId(softDeleteUtilBean.getOrderId());
				mesSoftDeleteHistory.setOrderNo(softDeleteUtilBean.getOrderNo());
				mesSoftDeleteHistory.setOrderItemId(softDeleteUtilBean.getOrderItemId());
				mesSoftDeleteHistory.setTableName(softDeleteUtilBean.getTableName());
				mesSoftDeleteHistory.setCreateTime(new Date());
				mesSoftDeleteHistory.setCreateUser(SpringWebUtils.getRequestUser());
				mesSoftDeleteHistory.setLastupdateTime(new Date());
				mesSoftDeleteHistory.setLastupdateUser(SpringWebUtils.getRequestUser());
				list.add(mesSoftDeleteHistory);
			} 
			if (softDeleteUtilBean.getSelfNumberLotName() != null) {
				mesSoftDeleteHistory = new MesSoftDeleteHistory();
				mesSoftDeleteHistory.setEffectRowCount(softDeleteTwBasLotHistory == null ? 0:softDeleteTwBasLotHistory);
				mesSoftDeleteHistory.setOperationType(softDeleteUtilBean.getOprationType());
				mesSoftDeleteHistory.setLotName(softDeleteUtilBean.getSelfNumberLotName()+"-A");
				mesSoftDeleteHistory.setSelfNumber(softDeleteUtilBean.getSelfNumber()+"-A");
				mesSoftDeleteHistory.setDumySelfNumber(softDeleteUtilBean.getSelfNumber());
				mesSoftDeleteHistory.setOrderId(softDeleteUtilBean.getOrderId());
				mesSoftDeleteHistory.setOrderNo(softDeleteUtilBean.getOrderNo());
				mesSoftDeleteHistory.setOrderItemId(softDeleteUtilBean.getOrderItemId());
				mesSoftDeleteHistory.setTableName(softDeleteUtilBean.getTableName());
				mesSoftDeleteHistory.setCreateTime(new Date());
				mesSoftDeleteHistory.setCreateUser(SpringWebUtils.getRequestUser());
				mesSoftDeleteHistory.setLastupdateTime(new Date());
				mesSoftDeleteHistory.setLastupdateUser(SpringWebUtils.getRequestUser());
				list.add(mesSoftDeleteHistory);
			}
		}
		return list;
	}
	
	/**
	 * 当订单取消时软删除关于lot中的数据
	 * tw_bas_lot
	 * */
	@Override
	public boolean SoftDeleteTwBasLot (SoftDeleteUtilBean softDeleteUtilBean) {
		List<MesSoftDeleteHistory> list = new ArrayList<MesSoftDeleteHistory> ();
		List<Integer> orderItemIds = softDeleteUtilBean.getOrderItemIds();
		boolean flag = false;
			List<TwBasLot> selectTwBasLotByOrderItems = twBasLotDao.selectTwBasLotByOrderItems(orderItemIds);
			List<TwBasLot> sorftList = new ArrayList<TwBasLot> ();
			List<TwBasLot> lotList = new ArrayList<TwBasLot> ();
			for (TwBasLot twBasLot : selectTwBasLotByOrderItems) {
				if (twBasLot.getStatus().equals("CREATED")) {
					lotList.add(twBasLot);
				} else {
					sorftList.add(twBasLot);
				}
			}
			
		if (softDeleteUtilBean.getCarType().equals("B") || softDeleteUtilBean.getCarType().equals("C") || softDeleteUtilBean.getCarType().equals("A")) {
			for (TwBasLot twBasLot : lotList) {
				softDeleteUtilBean.setSelfNumberLotName(twBasLot.getLotName());
				softDeleteUtilBean.setOrderId(twBasLot.getOrderId());
				softDeleteUtilBean.setOrderNo(twBasLot.getOrderNo());
				softDeleteUtilBean.setOrderItemId(twBasLot.getOrderItemId());
				softDeleteUtilBean.setSelfNumber(twBasLot.getSelfNumber());
				softDeleteUtilBean.setVin(twBasLot.getVin());
				List<MesSoftDeleteHistory> softDeleteTwBasLotHistory3 = softDeleteTwBasLotHistory(softDeleteUtilBean);
				for (MesSoftDeleteHistory mesSoftDeleteHistory : softDeleteTwBasLotHistory3) {list.add(mesSoftDeleteHistory);}
			}
			for (TwBasLot lot : sorftList) {
				if (lot.getVin() != null && lot.getVin() != "") {
					softDeleteUtilBean.setVinLotName(lot.getLotName());
					softDeleteUtilBean.setVin(lot.getVin());
					softDeleteUtilBean.setSelfNumberLotName(null);
					softDeleteUtilBean.setSelfNumber(null);
				} else if (lot.getSelfNumber() != null & lot.getSelfNumber() != null && (lot.getVin() == null || lot.getVin() == "")) {
					softDeleteUtilBean.setSelfNumberLotName(lot.getLotName());
					softDeleteUtilBean.setSelfNumber(lot.getSelfNumber());
					softDeleteUtilBean.setVinLotName(null);
					softDeleteUtilBean.setVin(null);
				}
				softDeleteUtilBean.setOrderId(lot.getOrderId());
				softDeleteUtilBean.setOrderNo(lot.getOrderNo());
				softDeleteUtilBean.setOrderItemId(lot.getOrderItemId());
				softDeleteUtilBean.setVin(lot.getVin());
				// 软删除 lot历史表  tw_bas_lot_history
				softDeleteUtilBean.setTableName("tw_bas_lot_history");
				softDeleteUtilBean.setRange(3);
				List<MesSoftDeleteHistory> softDeleteTwBasLotHistory = softDeleteTwBasLotHistory(softDeleteUtilBean);
				for (MesSoftDeleteHistory mesSoftDeleteHistory : softDeleteTwBasLotHistory) {list.add(mesSoftDeleteHistory);}
				
				// 软删除 lot的关键件消耗表  tw_bas_lot_consumpation
				softDeleteUtilBean.setTableName("tw_bas_lot_consumpation");
				softDeleteUtilBean.setRange(3);
				List<MesSoftDeleteHistory> softDeleteTwBasLotHistory2 = softDeleteTwBasLotHistory(softDeleteUtilBean);
				for (MesSoftDeleteHistory mesSoftDeleteHistory : softDeleteTwBasLotHistory2) {list.add(mesSoftDeleteHistory);}
				
//				// 软删除物料拉动表 te_mes_outbound
//				softDeleteUtilBean.setTableName("te_mes_outbound");
//				softDeleteUtilBean.setRange(1);
//				List<MesSoftDeleteHistory> softDeleteTwBasLotHistory3 = softDeleteTwBasLotHistory(softDeleteUtilBean);
//				for (MesSoftDeleteHistory mesSoftDeleteHistory : softDeleteTwBasLotHistory3) {list.add(mesSoftDeleteHistory);}
				
				// lot测试记录 tw_bas_lot_testing
				softDeleteUtilBean.setTableName("tw_bas_lot_testing");
				softDeleteUtilBean.setRange(3);
				List<MesSoftDeleteHistory> softDeleteTwBasLotHistory6 = softDeleteTwBasLotHistory(softDeleteUtilBean);
				for (MesSoftDeleteHistory mesSoftDeleteHistory : softDeleteTwBasLotHistory6) {list.add(mesSoftDeleteHistory);}
				
				// 软删除lot数据采集记录 tw_bas_lot_data_collection
				softDeleteUtilBean.setTableName("tw_bas_lot_data_collection");
				softDeleteUtilBean.setRange(3);
				List<MesSoftDeleteHistory> softDeleteTwBasLotHistory7 = softDeleteTwBasLotHistory(softDeleteUtilBean);
				for (MesSoftDeleteHistory mesSoftDeleteHistory : softDeleteTwBasLotHistory7) {list.add(mesSoftDeleteHistory);}
				
				// 软删除缺陷记录表 qm_bas_defect_record
				softDeleteUtilBean.setTableName("qm_bas_defect_record");
				softDeleteUtilBean.setRange(4);
				List<MesSoftDeleteHistory> softDeleteTwBasLotHistory4 = softDeleteTwBasLotHistory(softDeleteUtilBean);
				for (MesSoftDeleteHistory mesSoftDeleteHistory : softDeleteTwBasLotHistory4) {list.add(mesSoftDeleteHistory);}
				
				// 软删除维修记录 qm_bas_defectrepair_record
				softDeleteUtilBean.setTableName("qm_bas_defectrepair_record");
				softDeleteUtilBean.setRange(4);
				List<MesSoftDeleteHistory> softDeleteTwBasLotHistory5 = softDeleteTwBasLotHistory(softDeleteUtilBean);
				for (MesSoftDeleteHistory mesSoftDeleteHistory : softDeleteTwBasLotHistory5) {list.add(mesSoftDeleteHistory);}
				
				// 软删除lot表记录 tw_bas_lot
				softDeleteUtilBean.setTableName("tw_bas_lot");
				softDeleteUtilBean.setRange(4);
				List<MesSoftDeleteHistory> softDeleteTwBasLotHistory3 = softDeleteTwBasLotHistory(softDeleteUtilBean);
				for (MesSoftDeleteHistory mesSoftDeleteHistory : softDeleteTwBasLotHistory3) {list.add(mesSoftDeleteHistory);}
				
				// 软删除合拼表  tw_bas_lot_splice
				softDeleteUtilBean.setTableName("tw_bas_lot_splice");
				softDeleteUtilBean.setRange(4);
	            List<MesSoftDeleteHistory> softDeleteTwBasLotHistory8 = softDeleteTwBasLotHistory(softDeleteUtilBean);
				for (MesSoftDeleteHistory mesSoftDeleteHistory : softDeleteTwBasLotHistory8) {list.add(mesSoftDeleteHistory);}
				
				// 软删除检测线数据
				List<MesSoftDeleteHistory> sortDeleteTestLineDataByVin = sortDeleteTestLineDataByVin(lotList, softDeleteUtilBean.getOprationType());
				for (MesSoftDeleteHistory mesSoftDeleteHistory : sortDeleteTestLineDataByVin) {list.add(mesSoftDeleteHistory);}
				
				// 删除成功
				flag = true;
			}
		} 
		// 批量新增软删除历史表数据
		mesSoftDeleteHistoryDao.addsSoftDeleteHistory(list);
		return flag;
	}

}
